package com.sunflower.common.mybatis.query;

import com.baomidou.mybatisplus.core.conditions.ISqlSegment;
import com.baomidou.mybatisplus.core.conditions.SharedString;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;

import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

import static com.baomidou.mybatisplus.core.enums.SqlKeyword.*;

/**
 * @author: SunLuQuan
 * @Date: 2024年08月02日 21:39
 * @Description: CustomQueryWrapper
 * TODO
 */
public class CustomQueryWrapper<T> extends QueryWrapper<T> {

    public CustomQueryWrapper() {
        super((T) null);
    }

    public CustomQueryWrapper(T entity) {
        super(entity);
    }

    public CustomQueryWrapper(Class<T> entityClass) {
        super(entityClass);
    }

    public CustomQueryWrapper(T entity, String... columns) {
        super(entity, columns);
    }

    public QueryWrapper<T> orderBy(boolean condition, boolean isAsc, String column, ISqlSegment sqlSegment) {
        return maybeDo(condition, () -> appendSqlSegments(ORDER_BY, columnToSqlSegment(column),
                isAsc ? ASC : DESC, sqlSegment));
    }
}
